
#ifndef __DC_CHAN_H_
#define __DC_CHAN_H_



/* 底层访问 had 寄存器. */
int had_null_clock( void );
int had_ir8_write( uint8_t vir );
int had_dr32_write( uint32_t vdr );
int had_dr32_read( uint32_t *pvdr );
int had_dr32_write_by_index( uint8_t vir, uint32_t vdr );
int had_dr32_read_by_index( uint8_t vir, uint32_t *pvdr );



/* 通道消息 */
int had_umsg_send( umsg_t * pmsg );



typedef struct _tag_async_session had_async_session_t;

typedef int (*async_resp_cbkf)( had_async_session_t * psess, int tnum, uint32_t * prsp );

struct _tag_async_session {

    /* single link list */
    struct _tag_async_session * next;
    bool autofree;
    uint32_t stats;

    /* request data */
    int req_num;
    uint32_t req_ary[4];

    /* call back function for resp */
    async_resp_cbkf cbkf;
    void * parg;
    int step;

};


/**/
int had_async_alloc_session( async_resp_cbkf cbkf, void * parg, int autofree, had_async_session_t ** ppsess );

int had_async_post_requst( had_async_session_t * psess, int tnum, uint32_t * preq );
int had_async_refresh_requst( had_async_session_t * psess, int tnum, uint32_t * preq );
int had_async_refresh_callbk( had_async_session_t * psess, async_resp_cbkf cbkf, void * parg );
int had_async_proc_resp( int tnum, uint32_t * prsp );


/**/
void had_umsg_null_clock( umsg_t * pmsg );

void had_umsg_ir5_read( umsg_t * pmsg );
void had_umsg_ir5_write( umsg_t * pmsg );

void had_umsg_dr32_read( umsg_t * pmsg );
void had_umsg_dr32_write( umsg_t * pmsg );


void had_umsg_dm_read( umsg_t * pmsg );
void had_umsg_dm_write( umsg_t * pmsg );


void dmi_umsg_sync( umsg_t * pmsg );
void dmi_umsg_enter_debug( umsg_t * pmsg );
void dmi_umsg_leave_debug( umsg_t * pmsg );
void dmi_umsg_write_mem( umsg_t * pmsg );
void dmi_umsg_read_mem( umsg_t * pmsg );

void dmi_umsg_cpu_read( umsg_t * pmsg );
void dmi_umsg_cpu_write( umsg_t * pmsg );

/**/
#if 0
void had_umsg_debug_enter( umsg_t * pmsg );
void had_umsg_debug_leave( umsg_t * pmsg );
void had_umsg_ddc_write( umsg_t * pmsg );

void had_umsg_channel_start( umsg_t * pmsg );
void had_umsg_channel_stop( umsg_t * pmsg );
#endif


/* 设置 tck 的 freq . */
void dmi_umsg_tclk_set( umsg_t * pmsg );
void dmi_umsg_tclk_get( umsg_t * pmsg );


/**/
int had_mod_init(  uint tck, uint tms, uint32_t freq );

#endif

